#include "bank.h"

// 初始化账户
void init_account(Account *acc, const char *id, const char *name, double initial_balance) {
    if (acc == NULL) return;
    strcpy(acc->account_id, id);
    strcpy(acc->name, name);
    acc->balance = (initial_balance >= 0) ? initial_balance : 0; // 初始余额不能为负
}

// 存款操作（返回1成功，0失败）
int deposit(Account *acc, double amount) {
    if (acc == NULL || amount <= 0) {
        printf("存款失败：金额必须为正数！\n");
        return 0;
    }
    acc->balance += amount;
    printf("存款成功！存入金额：%.2f\n", amount);
    return 1;
}

// 取款操作（返回1成功，0失败）
int withdraw(Account *acc, double amount) {
    if (acc == NULL || amount <= 0) {
        printf("取款失败：金额必须为正数！\n");
        return 0;
    }
    if (amount > acc->balance) {
        printf("取款失败：余额不足！当前余额：%.2f\n", acc->balance);
        return 0;
    }
    acc->balance -= amount;
    printf("取款成功！取出金额：%.2f\n", amount);
    return 1;
}

// 查询余额
double check_balance(const Account *acc) {
    if (acc == NULL) return -1;
    return acc->balance;
}

// 显示账户信息
void show_account(const Account *acc) {
    if (acc == NULL) {
        printf("账户信息不存在！\n");
        return;
    }
    printf("\n===== 账户信息 =====\n");
    printf("账号：%s\n", acc->account_id);
    printf("姓名：%s\n", acc->name);
    printf("当前余额：%.2f\n", acc->balance);
    printf("====================\n");
}